"use strict";
exports.__esModule = true;
var State;
(function (State) {
    State["pending"] = "pending";
    State["resolved"] = "resolved";
    State["rejected"] = "rejected";
})(State || (State = {}));
var MyPromiseTS = /** @class */ (function () {
    function MyPromiseTS(exclutor) {
        this._state = State.pending;
        this._onResArry = [];
        exclutor(this._resove.bind(this), this._reject);
    }
    MyPromiseTS.prototype._resove = function (res) {
        var _this = this;
        //   定义promise时 就执行resove()回调
        console.log("this._resove()");
        this._value = res;
        this._state = State.resolved;
        console.log("this._resove() this._onResArry.length", this._onResArry.length);
        // this._onResArry.forEach((item) => {
        //   item(this._value);
        // });
        // 当promise中定义传入了then的执行回调后
        // while (this._onResArry.length > 0) {
        //   const itemRes = this._onResArry.shift();
        //   itemRes(this._value);
        // }
        var interval = setInterval(function () {
            if (_this._onResArry.length > 0) {
                var itemRes = _this._onResArry.shift();
                console.log("while{} itemRes()");
                itemRes(_this._value);
                clearInterval(interval);
            }
        }, 100);
    };
    MyPromiseTS.prototype._reject = function (err) { };
    MyPromiseTS.prototype.then = function (onRes) {
        this._onResArry.push(onRes);
    };
    MyPromiseTS.prototype["catch"] = function () { };
    return MyPromiseTS;
}());
exports["default"] = MyPromiseTS;
